﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;
using System.IO;

namespace Web
{
    public partial class register1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Search_Click(object sender, EventArgs e)
        {

        }

        private void SendMail(string mailTo, string username)
        {

            System.Net.Mail.SmtpClient client = new SmtpClient("smtp.163.com");

            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential("Lansendeer@163.com", "lansender");
            client.DeliveryMethod = SmtpDeliveryMethod.Network;

            MailAddress addressFrom = new MailAddress("lansendeer@163.com", "lansendeer");
            MailAddress addressTo = new MailAddress(mailTo, "mailTo");

            System.Net.Mail.MailMessage message = new MailMessage(addressFrom, addressTo);
            message.Subject = "注册成功";
            message.IsBodyHtml = true;
            message.Body = "感谢你注册Tiamat图片站。你的用户名为：" + username + "。" + "<br> Tiamat图片站-图片连接你我";
            message.Sender = new MailAddress("lansendeer@163.com");
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.IsBodyHtml = true;

            client.Send(message);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Button1.Attributes.Add("onclick", "return isValidate() ");

            BLL.UserBLL user = (BLL.UserBLL)BLLFAC.DataAccess.CreateUser();
            bool register = false;

            Model.UserInfo userInfo = new Model.UserInfo();

            string uname = Request["username"];
            string upsd = Request["password"];
            string umail = Request["email"];

            userInfo.setUI_userName(uname);
            userInfo.setUI_password(upsd);
            userInfo.setUI_mailAddr(umail);
            userInfo.setUI_nickName("");
            userInfo.setUI_gender(1);
            userInfo.setUI_birthday(DateTime.Now);
            userInfo.setUI_qqNumber("");
            userInfo.setUI_phoneNumber("");
            userInfo.setUI_country("");
            userInfo.setUI_province("");
            userInfo.setUI_city("");
            userInfo.setUI_regTime(System.DateTime.Now);
            userInfo.setUI_remark("");
            //DateTime dt = Convert.ToDateTime(System.DateTime.Now.ToShortDateString());
            //DateTime d = Convert.ToDateTime("12/31/9999 11:59:59 PM");
            //userInfo.setUI_regTime(System.DateTime.Now);
            //userInfo.setUI_regTime(d);
            register = user.register(userInfo);
            if (register)
            {
                SendMail(umail, uname);
                Response.Redirect("Default.aspx");

            }
            else
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}